﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;

public partial class DetailedBookmark : System.Web.UI.Page
{
    private Image GenerateThumb(String link)
    {
        WebsitesScreenshot.WebsitesScreenshot _WebsitesScreenshot = new WebsitesScreenshot.WebsitesScreenshot();
        WebsitesScreenshot.WebsitesScreenshot.Result _Result;
        Image ima = new Image();
        string path = null;
        path = Server.MapPath(".");
        _WebsitesScreenshot.ImageHeight = 160;
        _WebsitesScreenshot.ImageWidth = 160;
        _Result = _WebsitesScreenshot.CaptureWebpage("http://" + link);

        if (_Result == WebsitesScreenshot.WebsitesScreenshot.Result.Captured)
        {

            _WebsitesScreenshot.SaveImage(path + "\\" + link + ".jpg");
            ima.ImageUrl = link + ".jpg";
        }
        else if (_Result == WebsitesScreenshot.WebsitesScreenshot.Result.Failed)
        {
            Response.Write("");
            Response.Write("Failed");
        }
        else if (_Result == WebsitesScreenshot.WebsitesScreenshot.Result.Timeout)
        {
            Response.Write("");
            Response.Write("Timeout");
        }
        _WebsitesScreenshot.Dispose();
        return ima;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request["id"] == null)
        {
            Response.Redirect("~/404.aspx");
        }
        if (!Page.IsPostBack)
        {
            try
            {
                //SqlConnection conection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
                SqlConnection connection =
                    new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True");
                connection.Open();

                SqlCommand query = new SqlCommand("SELECT * FROM Bookmark where Index = @Index1", connection);
                
                SqlParameter param = new SqlParameter();
                param.ParameterName = "@Index1";
                param.Value = Request["id"];
                query.Parameters.Add(param);
                
                SqlDataReader reader = query.ExecuteReader();

                reader.Read();

                LTitlu.Text = (string)reader["Titlu"];
                //LOwner.Text = (string)reader["Owner"];
                //LDescriere.Text = (string)reader["Descriere"];
                //LVoturi.Text = (string)reader["Voturi"];
                //LTaguri.Text = (string)reader["Taguri"];
                //Imagine.ImageUrl  = (string)reader["Titlu"] + ".jpg";
                
                reader.Close();
                connection.Close();
            }
            catch (Exception er)
            {
                LTitlu.Text = (string) er.StackTrace;// throw;
            }
        }
        else
        {

        }
    }
}
